-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Add MCP server documentation #20634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MCP server documentation #20634
Conversation
|
Preview URL: https://c58405c8.preview.developers.cloudflare.com Files with changes (up to 15)
|
|
Howdy and thanks for contributing to our repo. We review internal PRs within 1 week. If it's something urgent or has been sitting without a comment, start a thread in the Developer Docs space internally. |
| import { MetaInfo, Render, Type, TypeScriptExample, WranglerConfig } from "~/components"; | ||
| import { Aside } from '@astrojs/starlight/components'; | ||
|
|
||
| [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) is an open standard that allows AI assistants & LLMs to interact with services directly. If you want users to access your service or product straight from their AI assistant, you can enable this by spinning up an MCP server for your application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
their AI assistant
Can we name some to orient people to what we mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i think some examples would be useful.
| ## Building an MCP Server on Cloudflare Workers | ||
|
|
||
| Normally, setting up an MCP server requires writing boilerplate code to handle routing, define types, and standing up a server that implements the MCP protocol. But with [Cloudflare Workers](/workers/), all the heavy lifting is done for you, so all you need to do is define your service's functionality as TypeScript methods on your Worker | ||
| Once deployed, your Worker becomes an MCP server that AI assistants (as long as they support MCP) can connect to and use to interact with your service. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
support MCP
Think saying "MCP client" helps orient the reader?
| Once deployed, your Worker becomes an MCP server that AI assistants (as long as they support MCP) can connect to and use to interact with your service. | ||
|
|
||
| <Aside type="caution"> | ||
| Remote MCP servers are not supported yet. The workers-mcp tooling creates a local proxy that forwards requests to your Worker, allowing the server to be used by an MCP client. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary callout at least as of today given there aren't really remote MCP clients?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO worthwhile otherwise it's confusing what actually happens here
| - Shared-secret security using Wrangler Secrets | ||
| - Installs a local proxy so you can access it from your MCP desktop clients (like Claude Desktop) | ||
|
|
||
| ### Set up the MCP Server |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would help to find a way to bring the code way up to the top as a kind of:
- MCP =
- On Workers, it's simple and TypeScript-native, it looks like this:
- Explain the code you just saw (the jsdoc == the tool description (link to MCP spec), the boilerplate is handled (link to
workers-mcplibrary so someone can read source code and understand)
Think faster we can show "here is code" and get someone saying "okay i get it, that is simple" — then after doing the step by step — then we don't bury the example
| /Users/username/path/to/my-new-worker/node_modules/.bin/workers-mcp run my-new-worker https://my-new-worker.username.workers.dev /Users/username/path/to/my-new-worker | ||
| ``` | ||
|
|
||
| #### Other MCP clients |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import { MetaInfo, Render, Type, TypeScriptExample, WranglerConfig } from "~/components"; | ||
| import { Aside } from '@astrojs/starlight/components'; | ||
|
|
||
| [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) is an open standard that allows AI assistants & LLMs to interact with services directly. If you want users to access your service or product straight from their AI assistant, you can enable this by spinning up an MCP server for your application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
substitute assitants with agents?
| import { MetaInfo, Render, Type, TypeScriptExample, WranglerConfig } from "~/components"; | ||
| import { Aside } from '@astrojs/starlight/components'; | ||
|
|
||
| [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) is an open standard that allows AI assistants & LLMs to interact with services directly. If you want users to access your service or product straight from their AI assistant, you can enable this by spinning up an MCP server for your application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i think some examples would be useful.
|
|
||
| ## Building an MCP Server on Cloudflare Workers | ||
|
|
||
| Normally, setting up an MCP server requires writing boilerplate code to handle routing, define types, and standing up a server that implements the MCP protocol. But with [Cloudflare Workers](/workers/), all the heavy lifting is done for you, so all you need to do is define your service's functionality as TypeScript methods on your Worker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't start here.
I would start with "In this guide, we will show you how to XYZ"
| * @return {string} The greeting message. | ||
| */ | ||
| sayHello(name: string) { | ||
| return `Hello from an MCP Worker, ${name}!`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be really good to have some other step that allows you to call an API. even like the weather one that's in the MCP docs. but really showing what this allows you to do which is integrate with stuff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think this is worthwhile
|
|
||
| In this guide, you will learn how to build and deploy a Model Context Protocol (MCP) server on Cloudflare Workers. | ||
|
|
||
| [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) is an open standard that allows AI agents and assistants (like [Claude Desktop](https://claude.ai/download), [Cursor](https://www.cursor.com/), or [Anthropic's Claude](https://www.anthropic.com/claude)) to interact with services directly. If you want users to access your service through an AI agent, you can spin up an MCP server for your application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this page could be helpful link: https://modelcontextprotocol.io/clients
| **How it works:** | ||
| * **TypeScript methods as MCP tools:** Each public method in your class is exposed as an MCP tool that agents can call. In this example, getWeather is the tool that fetches data from an external weather API. | ||
| * **Automatic tool documentation:** JSDoc comments define the tool description, parameters, and return values, so Claude knows exactly how to call your method and interpret the response. | ||
| * **Build-in MCP compatibility:** The `ProxyToSelf` class handles all MCP protocol requirements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite true and I think might misleads people — ProxyToSelf translates incoming requests into relevant JS RPC methods, but the actual handling of the MCP protocol, tool discovery, happens totally outside of the Worker, in the Node.js local proxy layer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * @return {string} The greeting message. | ||
| */ | ||
| sayHello(name: string) { | ||
| return `Hello from an MCP Worker, ${name}!`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think this is worthwhile
|
|
||
|
|
||
| ### Deploy the MCP server | ||
| Update your wrangler.toml with the appropriate configuration then deploy your Worker: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there's anything you actually need in your wrangler.toml can you include it here and have wrangler.jsonc and wrangler.toml such as here:
https://developers.cloudflare.com/workers/static-assets/binding/
PR Change SummaryAdded a new documentation page for building an MCP server on Cloudflare Workers, providing comprehensive setup instructions and example code.
Added Files
How can I customize these reviews?Check out the Hyperlint AI Reviewer docs for more information on how to customize the review. If you just want to ignore it on this PR, you can add the What is Hyperlint?Hyperlint is an AI agent that helps you write, edit, and maintain your documentation. Learn more about the Hyperlint AI reviewer and the checks that we can run on your documentation. |
Add MCP server documentation
Summary
New page in Agents documentation that explains how to build an MCP server on Workers. It includes setup instructions for creating an MCP server on Workers, example code, configuration instructions for MCP clients, and what's coming soon!
Screenshots (optional)
Documentation checklist